import { runtimeAppStore } from "@/stores/runtime";
import { invokeAPi, invokeAsyncAPi } from "@/xz-fn";
/**
 *  打开外部链接
 * @param {string} url 
 * @returns
 */
export function openLink(url: string) {
  invokeAPi("fq_open_url", url);
}

/**
 *  打开配置数据的链接
 * @param {string} url 
 * @returns
 */
export function jumpConfigURL(url: string | null){
  if(typeof url !== 'string') return false
  if(url === 'openUserCenter'){
    invokeAPi("fq_ShowUserCenter");
  } else if(url === 'openPayCenter'){
    invokeAPi("fq_ShowVipGuideCenter");
  } else if (url === 'openInstall') {
    fqShowInstall()
  } else if(url.match(/^http[s]?:\/\//)){
    invokeAPi("fq_open_url", url);
  }
}

export function fqShowInstall () {
  if (runtimeAppStore().checkInstallWinID) {
    invokeAPi('fq_NotifyWebMessageEx', runtimeAppStore().checkInstallWinID, {
      action: 'focus'
    })
    return
  }

  invokeAsyncAPi('fq_CreateWindow', {
    url: import.meta.env.VITE_APP_USERCENTER_ORIGIN + '/check-install',
    local_res: true,
    size: {
      cx: 390,
      cy: 296
    },
    parent_wnd: runtimeAppStore().mainWinID,
    payload: JSON.stringify({
      mainID: runtimeAppStore().mainWinID
    })
  }).then(res => {
    runtimeAppStore().setCheckInstallWinID(res as number)
  })
}